package com.huawei.controller;

/**
 * description
 *
 * @author cwx1134046
 * @since 2023-01-31
 */
public class MaxSubArray {
    public static int maxSubArray(int[] nums) {
        int sum = 0;
        int ans =nums[0];
        for (int num: nums) {
            if(sum > 0){
                sum = sum +num;
            }else{
                sum = num;
            }
            ans =Math.max(sum,ans);
        }
        return ans;
    }


    public static void main(String[] args) {
        int[] arr = {-2,1,-3,4,-1,2,1,-5,4};
        int i = maxSubArray(arr);
        System.out.println(i);
    }
}
